import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.1

ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("LogCat Client")

    menuBar: MenuBar {
        Menu {
            title: qsTr("File")
            MenuItem {
                action: clearAction
            }
            MenuItem {
                action:stopAction
            }
            MenuItem {
                text: qsTr("Exit")
                onTriggered: Qt.quit();
            }
        }
    }
    Action {
        id: clearAction
        text: "&Clear"
        shortcut: StandardKey.Refresh
        iconSource: "clear.png"
        onTriggered: gLogModel.clear()
        tooltip: "Clear all log"
    }
    Action {
        id: stopAction
        text: "&Stop"
        shortcut: StandardKey.Save
        iconSource: "stop.png"
        onTriggered: gLogCatClient.stop()
        tooltip: "stop read log"
    }
    toolBar: ToolBar {
        RowLayout {
            anchors.fill: parent
            ToolButton {
                action: clearAction
            }
            ToolButton {
                action:stopAction
            }
            ToolButton {
                iconSource: "warning.png"
            }
            Item { Layout.fillWidth: true }
            CheckBox {
                text: "Enabled"
                checked: true
            }
        }
    }

    TableView {
        anchors.fill:parent
        TableViewColumn { role: "rType"; title: "类型"; width: 50}
        TableViewColumn { role: "rMsgOnly"; title: "消息"; width: 500;elideMode:Text.ElideNone
            delegate:Text{
                anchors.fill: parent
                clip: true
//                width: parent.width
//                height: 100
//                wrapMode:Text.WrapAnywhere
                anchors.verticalCenter: parent.verticalCenter
                color: styleData.textColor
                elide: styleData.elideMode
                text: styleData.value
                MouseArea{
                    anchors.fill: parent
                    onClicked:
                    {
                        idloginfo.msg = gTools.toXml(styleData.value)
                        idloginfoarea.visible = true
                    }
                }
            }
        }
        TableViewColumn { role: "rFile"; title: "文件"; width: 200 }
        TableViewColumn { role: "rLine"; title: "行"; width: 50 }
        TableViewColumn { role: "rFunction"; title: "函数"; width: 200 ;elideMode:Text.ElideLeft}
        TableViewColumn { role: "rCategory"; title: "分类"; width: 200 }
        TableViewColumn { role: "rTime"; title: "时间"; width: 200 }
        model: gLogModel
    }

    Rectangle{
        id:idloginfoarea
        anchors.fill: parent
        anchors.bottomMargin:idsendarea.height
        color:"#70000000"
        visible: false
        MouseArea{
            anchors.fill: parent
            onClicked: parent.visible = false
        }

        Rectangle{
            id:idloginfo
            property alias msg: idlogmsg.text
            anchors.fill: parent
            anchors.margins: 64
            color:"white"
            Text {
                id: idlogmsg
                anchors.fill: parent
                anchors.margins: 20
                wrapMode:Text.WrapAnywhere
                color:"black"
            }
            MouseArea{
                anchors.fill: parent
            }
        }
    }
    Rectangle{
        id:idsendarea
        height: 60
        color: "#77e8f9"
        width:parent.width
        anchors.bottom: parent.bottom
        Rectangle{
            anchors.fill: idmsgtext
        }
        TextInput{
            id:idmsgtext
            anchors.fill: parent
            anchors.margins: 5
            anchors.rightMargin: 80
        }

        Button{
            anchors.right:parent.right
            width:76
            height:parent.height - 4
            text:"send"
            onClicked:
            {
                gLogCatClient.sendTestMsg(idmsgtext.text)
            }
        }
    }

    StartArea {
        anchors.centerIn: parent
        width: 200
        height: 100
    }
}
